package com.jcodecraeer.xrecyclerview.progressindicator.indicator;

import ohos.agp.animation.Animator;
import ohos.agp.animation.AnimatorValue;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;

import java.util.ArrayList;
import java.util.List;

public class BallScaleRippleMultipleIndicator extends BallScaleMultipleIndicator {
    @Override
    public void draw(Canvas canvas, Paint paint) {
        paint.setStyle(Paint.Style.STROKE_STYLE);
        paint.setStrokeWidth(3);
        super.draw(canvas, paint);
    }

    @Override
    public List<Animator> createAnimation() {
        List<Animator> animators=new ArrayList<>();
        long[] delays=new long[]{0, 200, 400};
        for (int i = 0; i < 3; i++) {
            final int index=i;
            AnimatorValue scaleAnim = new AnimatorValue();
            scaleAnim.setCurveType(Animator.CurveType.SMOOTH_STEP);
            scaleAnim.setDelay(delays[i]);
            scaleAnim.setDuration(1000);
            scaleAnim.setLoopedCount(-1);
            scaleAnim.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() {
                @Override
                public void onUpdate(AnimatorValue animatorValue, float v) {
                    scaleFloats[index] = v;
                    postInvalidate();
                }
            });
            scaleAnim.start();

            AnimatorValue alphaAnim = new AnimatorValue();
            alphaAnim.setCurveType(Animator.CurveType.SMOOTH_STEP);
            alphaAnim.setLoopedCount(-1);
            alphaAnim.setDuration(1000);
            alphaAnim.setDelay(delays[i]);
            alphaAnim.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() {
                @Override
                public void onUpdate(AnimatorValue animatorValue, float v) {
                    alphaInts[index] = (int)v;
                    postInvalidate();
                }
            });
            alphaAnim.start();
            animators.add(scaleAnim);
            animators.add(alphaAnim);
        }
        return animators;
    }
}
